package com.salt.modules.sys.feign;

import com.salt.common.constant.Common;
import com.salt.core.web.BaseController;
import com.salt.modules.sys.entity.DataRule;
import com.salt.modules.sys.entity.Role;
import com.salt.modules.sys.entity.User;
import com.salt.modules.sys.service.UserService;
import com.salt.modules.sys.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description
 * @Author salt
 * @Date 2020/7/28 17:23
 * @Version 1.0
 */
@RestController
@RequestMapping(Common.Service.SALT_ADMIN_USER_URL_PREFIX)
public class UserFeignController extends BaseController{

    @Autowired
    private UserService userService;

    @GetMapping("get")
    public User getUser(){
        return UserUtils.getUser();
    }

    /**
     * 根据ID获取用户
     * @param id
     * @return
     */
    @PostMapping("getById")
    public User get(@RequestParam("id") String id){
        return UserUtils.get(id);
    }

    /**
     * 根据ID的集合获取用户
     * @param ids
     * @return
     */
    @PostMapping("queryByIds")
    public List<User> queryByIds(@RequestParam("ids") List<String> ids) {
        return userService.queryByIds(ids);
    }

    @PostMapping("name")
    public User getByUserName(@RequestParam("name") String name){
        return UserUtils.getByUserName(name);
    }

    @GetMapping("getDataRuleList")
    public List<DataRule> getDataRuleList(){
        return UserUtils.getDataRuleList();
    }

    @GetMapping("getUserByLoginName")
    public User getUserByLoginName(String loginName){
        return UserUtils.getByLoginName(loginName);
    }

    @GetMapping("getRoleList")
    public List<Role> getRoleList(){
        return UserUtils.getRoleList();
    }

    @GetMapping("findUserByOfficeId")
    public List<User> findUserByOfficeId(String id){
        return userService.findUserByOfficeId(id);
    }

    @PostMapping("findList")
    public List<User> findList(User user){
        return userService.findList(user);
    }

    @PostMapping("getUserIdByRoleIds")
    public List<String> getUserIdByRoleIds(@RequestParam("roleIds") List<String> roleIds){
        List<String> userIdByRoleIds = userService.getUserIdByRoleIds(roleIds);
        return userIdByRoleIds;
    }

}
